package com.szrt.day20170424.ch01;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import org.junit.Test;


/**
 * 对象输出流
 * @author scott-13926583118
 * 2017年4月24日
 *
 */
public class ObjectOutputStreamTest {
	
	
	/**
	 * 先来的后关   栈  弹夹
	 * @throws Exception
	 */
	@Test
	public void writeObject() throws Exception {
		
		//侦察兵  student.data 子节流
		File file = new File("io1704/student.data");
		//小部队
		OutputStream os = new FileOutputStream(file);
		//大部队
		ObjectOutputStream  oos  = new ObjectOutputStream(os);
		
		
		Student student = new Student();
		student.setAge(24);
		student.setName("scott");
		
		oos.writeObject(student);
		
		
		oos.close();
		os.close();
		
		
	}
	
	@Test
	public void readObject() throws Exception {
		
		//侦察兵
		File file = new File("io1704/student.data");
		//小部队
		InputStream os = new FileInputStream(file);
		
		ObjectInputStream ios = new ObjectInputStream(os);
		
		Object object= ios.readObject();
		
		Student student = (Student)object;
		
		System.out.println(student);
		
		ios.close();
		os.close();
		
		
	}

}
